/*
 * 日志查看
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import './logInfo.dart';

class ViewLog extends StatelessWidget {
  final value;
  ViewLog({Key key, @required this.value}) : super(key: key);
  TextEditingController _fileController = new TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(value['userName']),
      ),
      body: _bodyWidget(),
    );
  }

  Widget _bodyWidget() {
    return Column(
      children: <Widget>[
        _fileDateState(),
        new SizedBox(
          height: ScreenUtil().setHeight(40),
        ),
        Expanded(
          child: Scrollbar(
            child: ListView.separated(
              itemCount: value['list'].length,
              //列表项构造器
              itemBuilder: (BuildContext context, int index) {
                final Axis slidableDirection = Axis.horizontal;
                return _getSlidableWithLists(context, index, slidableDirection);
              },
              //分割器构造器
              separatorBuilder: (context, index) => Divider(height: .0),
            ),
          ),
        ),
      ],
    );
  }

  /*
   * 填写日期
   */
  Widget _fileDateState() {
    _fileController.text = value['date'];
    return Container(
      margin: EdgeInsets.only(left: 10, right: 10),
      child: TextField(
        enabled: false,
        controller: _fileController,
        keyboardType: TextInputType.number,
        //设置键盘类型
        decoration: InputDecoration(
          labelText: "填写时间",
        ),
      ),
    );
  }

  /*
   * 展示列表（可左右删除的列表）
   */
  Widget _getSlidableWithLists(
      BuildContext context, int index, Axis direction) {
    var item = value['list'][index];
    var projectName = value['list'][index]['projectName'];
    return Slidable(
      key: Key(item['key'].toString()),
      direction: direction,
      actionExtentRatio: 0.25,
      actionPane: SlidableDrawerActionPane(),
      child: ListTile(
        title: new Text("$projectName"),
        subtitle: new Text(
          "${item['task']}",
          maxLines: 3,
          softWrap: true,
          overflow: TextOverflow.ellipsis,
        ),
        trailing: Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text('${item['completionDate']}'),
            Icon(Icons.chevron_right),
          ],
        ),
        onTap: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return LogInfo(value: item);
          }));
        },
      ),
    );
  }
}
